import json

# 读取JSON文件
with open('data.json', 'r', encoding='utf-8') as file:
    data = json.load(file)

# 准备写入结果的列表
result_lines = []

# 遍历每个page
for page_key in data:
    # 遍历每个元素
    for item in data[page_key]:
        # 解析 "0x10(37,16)" 格式的字符串
        hex_part = item.split('(')[0]  # 获取 "0x10"
        coord_part = item.split('(')[1].split(')')[0]  # 获取 "37,16"
        x, y = coord_part.split(',')
        
        # 生成两行代码
        result_lines.append(f'\tOLED_SetCursorXY({x}, {y});')
        result_lines.append(f'\tOLED_WriteData({hex_part});')

# 将结果写入code.txt文件
with open('code.txt', 'w', encoding='utf-8') as output_file:
    for line in result_lines:
        output_file.write(line + '\n')

print("代码已成功生成并写入code.txt文件")